package com.neuedu.nep.base;



import com.neuedu.nep.util.JwtUtil;
import com.neuedu.nep.vo.UserVO;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 许中
 * @create 2024-04-02 10:02
 * @description:
 */
public class BaseController {
//
//    @Resource
//    private UserService userService;
    /**
     * 获取当前线程池绑定的request对象
     */
    public HttpServletRequest request(){
        ServletRequestAttributes servletRequestAttributes= (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return servletRequestAttributes.getRequest();
    }

    /**
     * 获取当前线程池绑定的response对象
     */
    public HttpServletResponse response(){
        ServletRequestAttributes servletRequestAttributes= (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        return servletRequestAttributes.getResponse();
    }

//    public User user(){
//        String token=request().getHeader("token");
//        return userService.checkToken(token);
//    }

    public UserVO user(){
        String token=request().getHeader("token");
        UserVO userVO = JwtUtil.checkToken(token);
        return userVO;
    }

}
